how to truncate all tables laravel

47

MyModel::truncate();
foreach ($tableNames as $name) {
    //if you don't want to truncate migrations
    if ($name == 'migrations') {
        continue;
    }
    DB::table($name)->truncate();
}
Schema::enableForeignKeyConstraints();
Visitor::query()->truncate();
Schema::disableForeignKeyConstraints();
$tableNames = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames();

Comments

Submit
0 Comments